<link rel="stylesheet" href="__STATIC__/Huploadify.css">

<div id="upload_picture_{$addons_data['name']}"></div>

<input type="hidden" name="{$addons_data['name']}" id="{$addons_data['name']}" value="{$addons_data['value']}"/>

<div class="upload-img-box{$addons_data['name']}">
    {notempty name="$info[$addons_data['name']]"}
    <div class="upload-pre-item">
        
        <div style="cursor:pointer;" class="pic_del"  onclick="picDel{$addons_data.name}(this)" ><img src="__STATIC__/uploadify-cancel.png" /></div> 
        
        <a target="_blank"
                                    href="{$info[$addons_data['name']]|default='0'|get_picture_url}"><img
            style="max-width: {$addons_config['maxwidth']};"
            src="{$info[$addons_data['name']]|default='0'|get_picture_url}"/></a></div>
    {/notempty}
</div>

<script type="text/javascript">

    var maxwidth = "{$addons_config['maxwidth']}";

    $("#upload_picture_{$addons_data.name}").Huploadify({
        auto: true,
        height: 30,
        fileObjName: "file",
        buttonText: "上传图片",
        uploader: "{:url('File/pictureUpload',array('session_id'=>session_id()))}",
        width: 120,
        removeTimeout: 1,
        fileSizeLimit:"{$addons_config['max_size']}",
        fileTypeExts: "{$addons_config['allow_postfix']}",
        onUploadComplete: uploadPicture{$addons_data.name}
    });

    function uploadPicture{$addons_data.name}(file, data)
    {

        var data = $.parseJSON(data);

        $("#{$addons_data['name']}").val(data.id);

        var src = '/upload/picture/' + data.path;

        $(".upload-img-box{$addons_data['name']}").html('<div class="upload-pre-item">    <div style="cursor:pointer;" class="pic_del"  onclick="picDel{$addons_data.name}(this)" ><img src="__STATIC__/uploadify-cancel.png" /></div>        <a target="_blank" href="' + src + '"> <img style="max-width: ' + maxwidth + ';" src="' + src + '"/></a></div>');
    }
    
    function picDel{$addons_data.name}(obj)
    {
        
        var addons_name = "{$addons_data.name}";
        
        $("#" + addons_name).val(0);
        
        $(obj).parent().remove();
    }
</script>